﻿using System;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;

namespace YRevitJig
{
	public static class RevitExtensionAPI
	{
		public static XYZ PickPoint(this Selection selection, XYZ ptBase, UIDocument uiDoc, string statusPrompt = "单击选择点, 按 ESC 键退出。")
		{
			XYZ result = null;
			using (XLineJig xlineJig = new XLineJig(uiDoc))
			{
				xlineJig.StartPoint = ptBase;
				xlineJig.JigStage = XLineJig.EStage.eEndPt;
				result = uiDoc.Selection.PickPoint(statusPrompt);
			}
			return result;
		}

		public static XYZ PickOtherPoint(XYZ ptBase, UIDocument uiDoc, string statusPrompt = "单击选择点, 按 ESC 键退出。")
		{
			XYZ result = null;
			using (XLineJig xlineJig = new XLineJig(uiDoc))
			{
				xlineJig.JigStage = XLineJig.EStage.eEndPt;
				xlineJig.StartPoint = ptBase;
				result = uiDoc.Selection.PickPoint(statusPrompt);
			}
			return result;
		}

		public static XYZ PickRectOtherPoint(XYZ ptBase, UIDocument uiDoc, string statusPrompt = "单击选择点, 按 ESC 键退出。")
		{
			XYZ result = null;
			using (XRectJig xrectJig = new XRectJig(uiDoc))
			{
				xrectJig.JigStage = XRectJig.EStage.eEndPt;
				xrectJig.StartPoint = ptBase;
				xrectJig.RectAngle = uiDoc.ActiveView.RightDirection;
				result = uiDoc.Selection.PickPoint(statusPrompt);
			}
			return result;
		}

		public static XYZ PickArcMidPoint(XYZ ptStart, XYZ ptEnd, UIDocument uiDoc, string statusPrompt = "单击选择弧线上任意点, 按 ESC 键退出。")
		{
			XYZ result = null;
			using (XArc3PtJig xarc3PtJig = new XArc3PtJig(uiDoc))
			{
				xarc3PtJig.JigStage = XArc3PtJig.EStage.eOnCurvePt;
				xarc3PtJig.StartPoint = ptStart;
				xarc3PtJig.EndPoint = ptEnd;
				result = uiDoc.Selection.PickPoint(statusPrompt);
			}
			return result;
		}

		public static XYZ PickArcEndPoint(XYZ ptStart, XYZ ptCenter, UIDocument uiDoc, string statusPrompt = "单击选择弧线终点, 按 ESC 键退出。")
		{
			XYZ result = null;
			using (XArcJig xarcJig = new XArcJig(uiDoc))
			{
				xarcJig.JigStage = XArcJig.EStage.ePtEnd;
				xarcJig.StartPoint = ptStart;
				xarcJig.CenterPoint = ptCenter;
				result = uiDoc.Selection.PickPoint(statusPrompt);
			}
			return result;
		}
	}
}
